package com.devframe.srtp.client.handle;

import java.net.URI;

import org.jboss.netty.handler.codec.http.multipart.HttpDataFactory;
import org.jboss.netty.handler.codec.http.multipart.HttpPostRequestEncoder;
import org.jboss.netty.handler.codec.http.multipart.HttpPostRequestEncoder.ErrorDataEncoderException;

import com.devframe.srtp.SRTPConstants;
import com.devframe.srtp.util.enumobj.EnumSRTPAction;

public class ClientDeleteFileHandler extends ClientWrapFileHandler{

	private String filePath;
	
	public ClientDeleteFileHandler(String host,URI uri,String filePath,String userName,String pwd){
		super(host,uri,userName,pwd);
		this.filePath=filePath;
	}

	public HttpPostRequestEncoder wrapRequestData(HttpDataFactory factory) {
        HttpPostRequestEncoder bodyRequestEncoder = null;
        try {
            bodyRequestEncoder = new HttpPostRequestEncoder(factory, this.getRequest(), false); // true => multipart
        } catch (NullPointerException e) {
            e.printStackTrace();
        } catch (ErrorDataEncoderException e) {
            e.printStackTrace();
        }
        //设置参数
        try {
            bodyRequestEncoder.addBodyAttribute("getform", "POST");
            bodyRequestEncoder.addBodyAttribute(SRTPConstants.ACTION_KEY, EnumSRTPAction.DELETE_FILE.getValue());
            bodyRequestEncoder.addBodyAttribute(SRTPConstants.FILE_PATH_KEY, this.filePath);
            bodyRequestEncoder.addBodyAttribute(SRTPConstants.USER_NAME_KEY, super.getUserName());
            bodyRequestEncoder.addBodyAttribute(SRTPConstants.PWD_KEY, super.getPwd());
            
        } catch (NullPointerException e) {
            e.printStackTrace();
        } catch (ErrorDataEncoderException e) {
            e.printStackTrace();
        }
        try {
            bodyRequestEncoder.finalizeRequest();
        } catch (ErrorDataEncoderException e) {
            e.printStackTrace();
        }
		return bodyRequestEncoder;
	}
	
	
}
